<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('薪资变动纠错')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-editable-css"/>

</head>
<body class="gray-bg">
<form id="user-form" AUTOCOMPLETE="OFF">
    <div class="modal inmodal fade" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">选择薪资套类型</h4>
                </div>
                <div class="modal-body">
                    <p>
                        薪资套：<select id="pgid" name='pgid' class="form-control">
                    </select>
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" id="missmodal1" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" onclick="getPgid()" class="btn btn-primary">确认</button>
                </div>
            </div>
        </div>
    </div>
    <button type="button" id="modal1" class="btn btn-primary" data-toggle="modal"
            data-target="#myModal1">选择薪资套
    </button>


    <div class="modal inmodal fade" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">添加薪资变动历史</h4>
                </div>
                <div class="modal-body">
                    <p>
                        薪资套：<select id="pgid1" name='pgid1' class="form-control">
                    </select>
                    </p>
                    <p>
                        生效日期从:
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" id="Bgdate" class="form-control laydate-demo-2" placeholder="yyyy-MM-dd">
                    </div>
                    </p>
                    <p>
                        生效日期到:
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" id="EDdate" class="form-control laydate-demo-1" placeholder="yyyy-MM-dd">
                    </div>
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" id="missmodal2" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" onclick="addEmp()" class="btn btn-primary">确认</button>
                </div>
            </div>
        </div>
    </div>
    <button type="button" id="modal2" class="btn btn-primary" data-toggle="modal"
            data-target="#myModal2">选择薪资套
    </button>

    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <div class="select-list">
                        <ul>
                            <li>
                                工号：<input type="text" name="badge"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="add()">
                        <i class="fa fa-plus"></i> 添加员工
                    </a>
                    <a class="btn btn-danger" onclick="deleteEmp()">
                        <i class="fa fa-remove"></i> 删除员工
                    </a>
                    <a class="btn btn-warning" onclick="updateSalary()">
                        <i class="fa fa-download"></i> 更新薪资数据
                    </a>


                    &nbsp;&nbsp;
                    <a class="btn btn-success" onclick="threeProcedure('cSP_Change_toCheck')">
                        <i class="fa fa-plus"></i> 数据确认
                    </a>
                    <a class="btn btn-danger" onclick="threeProcedure('cSP_Change_toCancel')">
                        <i class="fa fa-remove"></i> 取消确认
                    </a>
                    <a class="btn btn-warning" onclick="threeProcedure('cSP_Change_to_Start')">
                        <i class="fa fa-download"></i> 执行处理
                    </a>


                </div>

                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</form>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>
<th:block th:include="include :: datetimepicker-js"/>


<script th:inline="javascript">
    var prefix = ctx + "SalaryChangeCorrection/SalaryChangeCorrection";
    var pgid;
    var xztList = [];
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        $(".datetimepicker-demo-2").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '.laydate-demo-2',
                type: 'date'
            });
        });

        $(".datetimepicker-demo-1").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '.laydate-demo-1',
                type: 'date'
            });
        });
        $("#modal1").attr("style", "display:none;");
        $("#modal2").attr("style", "display:none;");

        getSkypayGroups();
        //queryData();
    });


    /**
     * 获取薪资套列表
     */
    function getSkypayGroups() {
        var html = "";
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/getSkypayGroups",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#pgid").empty();
                var arry = data;
                for (var i = 0; i < arry.length; i++) {
                    xztList.push({value: arry[i].id, text: arry[i].title});
                    html += "<option value='"
                        + arry[i].id
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#pgid").append(html);
                $("#pgid1").append(html);

                $("#modal1").click();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function getPgid() {
        pgid = $("#pgid").val();
        $("#missmodal1").click();
        getData();
    }

    function getData() {
        var options = {
            code: "id",
            uniqueId: "id",
            pagination: false,
            url: prefix + "/list?pgid=" + pgid,
            onEditableSave: onEditableSave,
            height: $(window).height() - 120,
            createUrl: prefix + "/add",
            modalName: "薪资变动纠错",
            columns: [
                [{
                    checkbox: true,
                    rowspan: 2,
                    valign: "middle"
                },
                    {
                        field: 'badge', title: '工号',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'name', title: '姓名',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'compName', title: '公司名称',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'depName', title: '部门名称',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'jobName', title: '工作岗位',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'empStatusName', title: '员工状态',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'pzidName', title: '薪资区域',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'effectdate', title: '生效日期',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'regtime', title: '登记时间',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'regbyName', title: '登记人',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'initialized', title: '？确认',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'initializedbyName', title: '确认人',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'initialiZedTime', title: '确认时间',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'closed', title: '？封存',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'closedByName', title: '封存人',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'closedTime', title: '封存时间',
                        rowspan: 2,
                        valign: "middle"
                    },
                    {
                        field: 'remark', title: '备注',
                        rowspan: 2,
                        valign: "middle"
                    },
                ],
                [],
            ]
        };

        //利用ajax动态获取项目
        $.ajax({
            async: false,
            url: ctx + "salaryAdmin/findProObject",
            data: {
                "pgid": pgid
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var text = data[i].title.replace('（', '').replace("）", '');
                    var stdId = data[i].id;
                    var field = text + "@@@" + stdId;
                    options.columns[0].push({
                        title: data[i].title,
                        rowspan: 1,
                        colspan: 2,
                        align: "center"
                    });
                    options.columns[1].push({
                        title: '原数值',
                        rowspan: 1,
                        field: field + "@@@旧"
                    });
                    options.columns[1].push({
                        title: '数值',
                        rowspan: 1,
                        field: field + "@@@新", editable: true
                    });
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
        $.table.init(options);
    }

    function add() {
        $("#modal2").click();
    }

    function addEmp() {
        var pgid1 = $("#pgid1").val();
        var Bgdate = $("#Bgdate").val();
        var EDdate = $("#EDdate").val();
        var cs = pgid1 + "&Bgdate=" + Bgdate + "&EDdate=" + EDdate;
        $.operate.edit_currency("添加", '员工', cs, "公司", prefix + "/addEmp", "xiao");
    }

    function deleteEmp() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        var allid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allid += row[i].id
            } else {
                allid += row[i].id + ","
            }
        }
        $.ajax({
            url: ctx + "SalaryChangeCorrection/SalaryChangeCorrection/deleteEmp",
            data: {
                "allid": allid
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.data == null) {
                    $.modal.alertWarning(data.message);
                } else {
                    $.modal.alertSuccess(data.data);
                }
                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function updateSalary() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        var allid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allid += row[i].id
            } else {
                allid += row[i].id + ","
            }
        }
        $.ajax({
            url: ctx + "SalaryChangeCorrection/SalaryChangeCorrection/changeStart",
            data: {
                "allid": allid
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.data == null) {
                    $.modal.alertWarning(data.message);
                } else {
                    $.modal.alertSuccess(data.data);
                }
                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }


    function threeProcedure(type) {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        }
        var allId = "";
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allId += row[i].id
            } else {
                allId += row[i].id + ","
            }
        }
        $.ajax({
            url: prefix + "/threeProcedure",
            data: {"allId": allId, "type": type},
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.data == null) {
                    $.modal.alertWarning(data.message);
                } else {
                    $.modal.alertSuccess(data.data);
                }

                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }


    function onEditableSave(field, row, oldValue, $el) {
        var cityId = row.peid;
        var benefitTypeAndXl = field;
        var updVal = row[field];

        $.ajax({
            url: prefix + "/updateSalary",
            data: {"cityId": cityId, "benefitTypeAndXl": benefitTypeAndXl, "updVal": updVal},
            type: "post",
            dataType: "json",
            success: function (data) {
                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }


</script>
</body>
</html>